<body>
    <h1></h1>
</body>
<script>
    var fonts = []
    setInterval(function() {

// 血条-1

// var xue = parseInt(document.querySelector('.xue').style.width)
// document.querySelector('.xue').style.width = xue-1
// 造星
var fontObj = document.createElement('div')
fontObj.className = 'font'

var min = 0
var max = 25
var index = Math.floor( Math.random()*(max-min+1)+min )
var font = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')[index]
fontObj.innerText = font
fonts.push(font)
// 随机宽高
// var min = 20
// var max = 40
// var temp=Math.floor(Math.random()*(max-min+1)+min)
// imgObj.width = temp
// 随机位置
var leftMin = 0
var leftMax = (window. innerWidth || document . documentElement . clientWidth)
var left =Math. floor( Math. random( )* ( leftMax- leftMin+1) +leftMin)
var topMin = 0
var topMax = (window. innerHeight|| document . documentElement . clientHeight)
var top = Math. floor( Math. random( )* (topMax- topMin+1)+topMin)
fontObj.style.position = 'absolute'
fontObj.style.left = left+'px'
fontObj.style.top = top+'px'
// 追加到页面
document.body.appendChild(fontObj)
} ,1000)

// 网页加事件监控键盘松开
document.onkeyup = function(evt){
        var e = evt || window.event
        console.log('松开了' ,e.key)

        var fonts = document.querySelectorAll('div.font')
        fonts.forEach(function(item){ //item就是每个存放字母的盒模型

            if(item.innerText.toLowerCase() === e.key.toLowerCase()){
                // 删除
                document.body.removeChild(item)
                // 统计  +1
                var num = parseInt(document.querySelector('h1').innerText)
                document.querySelector('h1').innerText = num+1
            }
        })
    }
</script>